package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.Product;
import com.example.demo.mapper.ProductMapper;
import com.example.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 商品服务实现类
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public void addProduct(Product product) {
        productMapper.insert(product);
    }

    @Override
    public Product updateProduct(Product product) {
        productMapper.updateById(product);
        return product;
    }

    @Override
    public void deleteProduct(Integer productId) {
        productMapper.deleteById(productId);
    }

    @Override
    public Product getProduct(Integer productId) {
        return productMapper.selectById(productId);
    }

    @Override
    public List<Product> getAvailableProducts() {
        return productMapper.findAvailableProducts();
    }

    @Override
    public void updateStock(Integer productId, Integer stock) {
        Product product = getProduct(productId);
        if (product != null) {
            product.setStock(stock);
            updateProduct(product);
        }
    }

    @Override
    public Product getProductById(Integer productId) {
        return null;
    }

    @Override
    public List<Product> getAllProducts() {
        return productMapper.all();
    }

    @Override
    public List<Product> getProductsByCategory(Integer categoryId) {
        return List.of();
    }

    @Override
    public List<Product> getProductsByMerchant(Integer merchantId) {
        return List.of();
    }
//是宠物
    @Override
    public List<Product> getPetProducts(boolean isPet) {
        int a=1;
        if (isPet){
            a=1;
        }else{
            a=0;
        }
        return productMapper.allt(a);
    }

    @Override
    public List<Product> searchProducts(String keyword) {
        return List.of();
    }

    @Override
    public List<Product> getProductsByPriceRange(BigDecimal minPrice, BigDecimal maxPrice) {
        return List.of();
    }

    @Override
    public IPage<Product> page(Page<Product> page) {
        return null;
    }

    @Override
    public Product createProduct(Product product) {
        return null;
    }
}